<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Share</title>
</head>

<body>

<cfset collab_code = Trim(form.argid) />
<cfset thecontent  = Trim(form.content) />

<cfset cont_arr    = ArrayNew(1) />
<cfset cont_arr    = ListToArray( thecontent, '<>', 'no' ) />

<cfset len_arr     = ArrayLen(cont_arr) />

           <cfquery name="isOPEN" datasource="#client.company_dsn#" maxrows="2">
            
                SELECT COLLABCODE
                  FROM ECRTCOLLAB
                 WHERE USERID  = '#client.USERID#' AND COLLABCODE = '#collab_code#' AND ISALLOWED = 'Y';
            
            </cfquery>

<!---self--->
     <cfif isOPEN.RecordCount LT 1>

        <cfquery name="getPIDNO" datasource="#client.company_dsn#" maxrows="1">
        
            SELECT #client.mainpk# AS PERSONNELIDNO, FIRSTNAME, LASTNAME FROM #client.MAINTABLE#
             WHERE GUID = '#client.GUID#'
             
        </cfquery>
        
        <cfquery name="getUserInfo" datasource="#client.company_dsn#" maxrows="1">
        
            SELECT AVATAR
              FROM ECRGMYIBOSE
             WHERE PERSONNELIDNO = '#getPIDNO.PERSONNELIDNO#';
             
        </cfquery>
    

        <cfif getUserInfo.AVATAR is "NULL" or getUserInfo.AVATAR eq "">
			<cfset useravatar = "no_avatar.png">
        <cfelse>
            <cfset useravatar = getUserInfo.AVATAR>
        </cfif>
        
        <cfset myfullname     = '#getPIDNO.FIRSTNAME# #getPIDNO.LASTNAME#' />
        <cfset myavatarreal   = '#client.image_path#pics201/#useravatar#' />

<cfset uuiidd    = CreateUUID() />
<cfset todaydate = DateFormat(Now(), "YYYY-MM-DD") />
<cfset todaytime = TimeFormat(Now(), "HH:MM:SS") />
<cfset todaydate = "#todaydate# #todaytime#" />
 <cfquery name="insertME" datasource="#client.company_dsn#">
 
	INSERT INTO ECRTCOLLAB ( RIGHTSID, COLLABCODE, ISALLOWED, USERID, COUNT, DATECREATED, USERGRPID_FK, FOLDERCODE )
	VALUES ( '#uuiidd#', '#collab_code#', 'Y', '#client.USERID#', 0, '#todaydate#', '#myfullname#', '#myavatarreal#');
    
 </cfquery>
 
<!---end self--->  
</cfif>

<cfoutput>~trimstartshere2~</cfoutput>
<cfloop index="count" from="1" to="#len_arr#">

	<cfset valtest = "#Trim(cont_arr[count])#" />
   
    <cfset val2    = ListGetAt(valtest, 1, '~', 'yes') />
   
   
    <cfif Ucase(val2) EQ 'SHARED'>
    	
    
    <cfelseif Ucase(val2) EQ 'GROUP'> <!---group--->
    
    	<cfset val_description    = Trim(ListGetAt(valtest, 2, '~')) />
        
        <cfquery name="getGroupID" datasource="#client.global_dsn#" maxrows="1">
        
            SELECT USERGRPID
              FROM EGRGUSERGROUPS
             WHERE DESCRIPTION  = '#val_description#';
        
        </cfquery>
        
        <cfquery name="getUserID" datasource="#client.global_dsn#">
        
            SELECT USERGRPMEMBERSIDX
              FROM EGRGROLEINDEX
             WHERE USERGRPID_FK  = '#getGroupID.USERGRPID#';
        
        </cfquery>
        
        <cfloop query="getUserID">
        
            <cfquery name="isexist" datasource="#client.company_dsn#" maxrows="2">
            
                SELECT COLLABCODE
                  FROM ECRTCOLLAB
                 WHERE USERID  = '#getUserID.USERGRPMEMBERSIDX#' AND COLLABCODE = '#collab_code#';
            
            </cfquery>
            
            <cfif isexist.RecordCount LT 1>
            
            	<!---for group--->
                
                <cfquery name="getGUID" datasource="#client.global_dsn#" maxrows="1">
                
                    SELECT A.GUID AS GUID, B.MAINTABLE AS MAINTABLE, B.MAINKEY AS MAINKEY
                      FROM EGRGUSERMASTER A JOIN 
                      <cfif Ucase(client.DBMS) EQ 'MYSQL'>
		             	#CLIENT.COMPANY_DSN#.CLKUSERTYPE B
					 <cfelseif Ucase(client.DBMS) EQ 'MSSQL'>
					 	#CLIENT.COMPANY_DSN#.dbo.CLKUSERTYPE B
					 </cfif> 
                       ON B.USERTYPE = A.USERTYPE 
                     WHERE USERID = '#getUserID.USERGRPMEMBERSIDX#';
                     
                </cfquery>
                
                <cfquery name="getPIDNO" datasource="#client.company_dsn#" maxrows="1">
                
                    SELECT #getGUID.MAINKEY# AS PERSONNELIDNO, FIRSTNAME, LASTNAME FROM #getGUID.MAINTABLE#
                     WHERE GUID = '#getGUID.GUID#'
                     
                </cfquery>
                
                <cfquery name="getUserInfo" datasource="#client.company_dsn#" maxrows="1">
                
                    SELECT AVATAR
                      FROM ECRGMYIBOSE
                     WHERE PERSONNELIDNO = '#getPIDNO.PERSONNELIDNO#';
                     
                </cfquery>
            
        
                <cfif getUserInfo.AVATAR is "NULL" or getUserInfo.AVATAR eq "">
                    <cfset useravatar = "no_avatar.png">
                <cfelse>
                    <cfset useravatar = getUserInfo.AVATAR>
                </cfif>
                <cfset myfullname     = '#getPIDNO.FIRSTNAME# #getPIDNO.LASTNAME#' />
                <cfset myavatarreal   = '#client.image_path#pics201/#useravatar#' />
                <!---end for group--->
            
                <cfset uuiidd    = CreateUUID() />
                <cfset todaydate = DateFormat(Now(), "YYYY-MM-DD") />
				<cfset todaytime = TimeFormat(Now(), "HH:MM:SS") />
                <cfset todaydate = "#todaydate# #todaytime#" />
                
                 <cfquery name="insertRT" datasource="#client.company_dsn#">
                 
                    INSERT INTO ECRTCOLLAB ( RIGHTSID, COLLABCODE, ISALLOWED, USERID, COUNT, DATECREATED, USERGRPID_FK, FOLDERCODE )
                    VALUES ( '#uuiidd#', '#collab_code#', 'Y', '#getUserID.USERGRPMEMBERSIDX#', 1, '#todaydate#', '#myfullname#', '#myavatarreal#');
                    
                 </cfquery>
                
            </cfif>
        
        </cfloop>
        
    	
   
    <cfelse> <!---individual--->
    
    	<cfset val_guid    = Trim(ListGetAt(valtest, 1, '~')) />
        
        <cfquery name="getUserID" datasource="#client.global_dsn#" maxrows="1">
        
            SELECT USERID
              FROM EGRGUSERMASTER
             WHERE GUID  = '#val_guid#';
        
        </cfquery>
        
        <cfquery name="tExist" datasource="#client.company_dsn#" maxrows="2">
        
            SELECT COLLABCODE
              FROM ECRTCOLLAB
             WHERE USERID  = '#getUserID.USERID#' AND COLLABCODE = '#collab_code#' AND COLLABCODE IS NOT NULL;
        
        </cfquery>
        
        <cfif tExist.recordcount LT 1>
        
        	<!---for one--->
              <cfquery name="getPIDNO" datasource="#client.company_dsn#" maxrows="1">
        
	            SELECT #client.mainpk# AS PERSONNELIDNO, FIRSTNAME, LASTNAME FROM #client.MAINTABLE#
	             WHERE GUID = '#val_guid#'
	             
	          </cfquery>
                
                <cfquery name="getUserInfo" datasource="#client.company_dsn#" maxrows="1">
                
                    SELECT AVATAR
                      FROM ECRGMYIBOSE
                     WHERE PERSONNELIDNO = '#getPIDNO.PERSONNELIDNO#';
                     
                </cfquery>
            
        
                <cfif getUserInfo.AVATAR is "NULL" or getUserInfo.AVATAR eq "">
                    <cfset useravatar = "no_avatar.png">
                <cfelse>
                    <cfset useravatar = getUserInfo.AVATAR>
                </cfif>
                <cfset myfullname     = '#getPIDNO.FIRSTNAME# #getPIDNO.LASTNAME#' />
                <cfset myavatarreal   = '#client.image_path#pics201/#useravatar#' />
            <!---end for one--->
        
        	<cfset uuiidd    = CreateUUID() />    
            
            <cfset guuiidd   = CreateUUID() />
			<cfset todaydate = DateFormat(Now(), "YYYY-MM-DD") />
            <cfset todaytime = TimeFormat(Now(), "HH:MM:SS") />
            <cfset todaydate = "#todaydate# #todaytime#" />
            
            <cfquery name="insertRT" datasource="#client.company_dsn#">
            
                INSERT INTO ECRTCOLLAB ( RIGHTSID, COLLABCODE, ISALLOWED, USERID, COUNT, DATECREATED, USERGRPID_FK, FOLDERCODE )
                VALUES ( '#uuiidd#', '#collab_code#', 'Y', '#getUserID.USERID#', 1, '#todaydate#', '#myfullname#', '#myavatarreal#');
                
            </cfquery>
            
        </cfif>
    
    </cfif>


</cfloop>
Successful!
<cfoutput>~trimendshere2~</cfoutput>

</body>
</html>
